// -----------------------------------------------------------------------
//  <copyright file="PageQueryBase.cs" company="LiuliuSoft">
//      Copyright (c) 2022-2024 DaprPlus. All rights reserved.
//  </copyright>
//  <site>https://www.dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2024-04-13 0:54</last-date>
// -----------------------------------------------------------------------

using DaprPlus.Filters;

using OSharp.Filter;


namespace DaprPlus.MediatR;

/// <summary>
/// 页数据查询基类
/// </summary>
/// <typeparam name="TResponse"></typeparam>
public class PageQuery<TResponse> : IRequest<TResponse>, IQuery
{
    /// <summary>
    /// 获取或设置 分页条件信息
    /// </summary>
    public PageCondition PageCondition { get; set; } = new(1, 20);

    /// <summary>
    /// 获取或设置 查询条件组
    /// </summary>
    public FilterGroup FilterGroup { get; set; } = new();

    /// <summary>
    /// 添加默认排序条件，只有排序为空时有效
    /// </summary>
    public void AddDefaultSortCondition(params SortCondition[] sortConditions)
    {
        Check.NotNull(sortConditions, nameof(sortConditions));
        if (PageCondition.SortConditions.Length == 0)
        {
            PageCondition.SortConditions = sortConditions;
        }
    }
}
